package pl.mdziedzic.unittests;

import java.util.Calendar;

import pl.mdziedzic.unittests.services.RequestContext;


public class AuctionBuilder {
	static final String AUCTION_NAME = "Example auction";
	static final int BUY_NOW_PRICE = 1000;

	User user;
	RequestContext context;
	Calendar startTime;
	Calendar endTime;

	public static AuctionBuilder anAuction(){
		return new AuctionBuilder();
	}

	public AuctionBuilder() {
		user = new User("example.user");

		startTime = Calendar.getInstance();
		startTime.add(Calendar.DATE, 1);

		endTime = (Calendar) startTime.clone();
		endTime.add(Calendar.DATE, 7);
		
	}
	
	public AuctionBuilder withUser(User user){
		this.user = user;
		return this;
	}
	
	public Auction build(){
		context = new RequestContext(user);
		CreateAuctionRequest request = CreateAuctionRequest
				.createBuyNowAuction(AUCTION_NAME, startTime, endTime,
						BUY_NOW_PRICE);
		return new Auction(context, request);
	}
	
	public AuctionBuilder withSystemClockMoved() {
		Calendar now = context.getNow();
		now.add(Calendar.DATE, 1);
		now.add(Calendar.SECOND, 1);
		return this;
	}
}
